<?php

namespace App\Http\Resources;

use App\Models\PoolUp;

class PoolResource extends Resource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        $user = auth()->user();
        return [
            'id' => $this->id,
            'title' => $this->title,
            'name' => $this->name,
            'img' => $this->img,
            'status' => $this->status,
            'up' => $this->up,
            'introduction' => $this->introduction,
            'created_at' => (string)$this->created_at,
            'my_up' => ($user && PoolUp::where('user_id', $user->id)->exists()) ? 1 : 0
        ];
    }
}
